package com.atguigu.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ：MJS
 * @date ：Created in 2021/4/26  20:39
 * @description：运用线程池的方式进行卖票
 * 三个 售票员  卖  50张票
 */
public class SaleTicketOfThreadPool {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);//3个售票员

        try{
            //卖50张票
            for (int i = 1; i <= 50; i++) {
                int finalI=i;
                threadPool.submit(()->{
                    System.out.println(Thread.currentThread().getName()+"\t"+"卖出了第"+finalI+"张票");
                });
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
           threadPool.shutdown();
        }
    }
}
